package com.chy.线程;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.ArrayList;

public class Test02Atomicity {
    private static int number = 0;

    public static void main(String[] args) throws InterruptedException {
        Runnable increment = () -> {
            for (int i = 0; i < 1000; i++) {
                number++;
            }
        };
    ArrayList<Thread> ts = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        Thread t = new Thread(increment);
        t.start();
        //t.join();
        ts.add(t);
    }for (Thread t : ts) {
        t.join();
    }
    System.out.println("number = " + number); } }
